const Validator = require('validator');
const isEmpty = require('./isEmpty')

module.exports = function validationProfileIpt(data){
  let errors = {};
  data.handle = !isEmpty(data.handle) ? data.handle : '';
  data.status = !isEmpty(data.status) ? data.status : '';
  data.skills = !isEmpty(data.skills) ? data.skills : '';

  if(!Validator.isLength(data.handle, { min:2, max:40 })){
    errors.handle = "handle的长度不能小于2位且不能大于40位";
  }
  // 这个isEmpty是Validator的方法
  if(Validator.isEmpty(data.handle)){
    errors.handle = "名字不能为空"
  }

  if(Validator.isEmpty(data.status)){
    errors.status = "status不能为空"
  }
  if(Validator.isEmpty(data.skills)){
    errors.skills = "skills不能为空"
  }

  if(!Validator.isEmpty(data.website)){
    if(!Validator.isURL(data.website)){
      error.website = "URL不合法"
    }
  }

  return {
    errors: errors,
    // 注意这个isEmpty 是自己写的方法
    isValid: isEmpty(errors),
  }
}